from django.contrib import admin
from .models import *

# Register your models here.
@admin.register(FileCacheBucket)
class FileCacheBucketAdmin(admin.ModelAdmin):
    list_display = ['name', 'max_size', 'used_size', 'free_size', 'count']
    actions = ['empty']

    def empty(self, request, queryset):
        for bucket in queryset:
            try:
                bucket.clear_cache(ensure_free_size=bucket.max_size)
            except Exception as e:
                print type(e), e

@admin.register(FileCache)
class FileCacheAdmin(admin.ModelAdmin):
    list_display = ['uri', 'bucket', 'storage_name', 'size', 'filetype', 'ext', 'access_dt']
    list_filter = ['bucket', 'filetype', 'ext', 'access_dt']

